{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# File Directory\n",
    "This covers how to load all documents in a directory.\n",
    "\n",
    "这涵盖了如何加载目录中的所有文档。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|██████████| 2/2 [00:00<?, ?it/s]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[Document(page_content='meow meow🐱 \\n meow meow🐱 \\n meow😻😻', metadata={'source': '..\\\\data\\\\meow.txt'}),\n",
       " Document(page_content='Team,Payroll (millions),Wins\\nNationals,81.34,98\\nReds,82.20,97\\nYankees,197.96,95', metadata={'source': '..\\\\data\\\\mlb_teams_2012.csv'})]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from langchain_community.document_loaders import (\n",
    "    DirectoryLoader,\n",
    "    TextLoader\n",
    ")\n",
    "# windows下需要pip install python-magic-bin\n",
    "loader = DirectoryLoader('../data',               # 文件夹路径\n",
    "                         glob=\"**/*\",             # 限制加载文件的类型\n",
    "                         show_progress=True,      # 进度条\n",
    "                         use_multithreading=True, # 多线程加载\n",
    "                         loader_cls=TextLoader,   # 默认是UnstructuredFileLoader，可更换\n",
    "                         silent_errors=True,      # 忽略错误\n",
    "                         loader_kwargs={'autodetect_encoding': True} # 自动检查编码\n",
    "                        )\n",
    "loader.load()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "langchain0_1",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
